package com.gateway.system.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gateway.config.superclass.SuperService;
import com.gateway.system.domain.dto.BasicRouteDto;
import com.gateway.system.domain.entity.BasicRoute;
import com.gateway.system.mapper.BasicRouteMapper;
import com.gateway.system.service.BasicRouteService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Huangkai
 */
@Slf4j
@Service
public class BasicRouteServiceImpl extends SuperService<BasicRouteMapper, BasicRoute> implements BasicRouteService {

    @Autowired
    BasicRouteMapper basicRouteMapper;

    @Override
    public List<BasicRouteDto> selectBaseRouteList() {
        LambdaQueryWrapper<BasicRoute> wrapper = new QueryWrapper<BasicRoute>().lambda();
        List<BasicRoute> baseRouteList = basicRouteMapper.selectList(wrapper);
        if(baseRouteList != null && baseRouteList.size() > 0){
            String arrayStr = JSONArray.toJSONString(baseRouteList);
            JSONArray jsonArray = JSONArray.parseArray(arrayStr);
            List<BasicRouteDto> baseRouteDtoList = jsonArray.toJavaList(BasicRouteDto.class);
            return baseRouteDtoList;
        }
        return null;
    }
}
